<?php
/** 
 * $Source: /cvsroot/pn-commerce/pn-commerce/pntemplates/plugins/function.pncRememberItem.php,v $
 * $Author: landseer $
 * $Revision: 1.1 $
 * $Date: 2004/01/28 11:27:58 $
 *
 * Type: Function
 *
 * remembers an items id in a session variable
 *@param params['ItemID'] int the id of the item
 *@returns nothing
 */
function smarty_function_pncRememberItem($params, &$smarty)
{
    extract($params);

    if( !$ItemID )
    {
        $smarty->trigger_error( "pncRememberItem: missing parameter ItemID" );
    }
    if( !pnModAPILoad( 'pncommerce', 'user' ) )
    {
        $smarty->trigger_error( 'pncRememberItem: cannot load userapi', E_ERROR );
        return false;
    }
    $lv = unserialize( pnSessionGetVar( 'pncLastSeenItems' ) );
    $rem = pnModGetVar( 'pncommerce', 'MaxItemsToRemember' );
    if( !isset( $rem ) )
    {
        $rem = 3;
        pnModSetVar( 'pncommerce', 'MaxItemsToRemember', 3 );
    }
    if( !is_array ($lv) ) 
    {
        $lv = array();
    }
    $keys = array_flip( $lv );
    if( array_key_exists( $ItemID, $keys ) == false )
    {
        array_unshift( $lv, $ItemID );
        $newlv = array_slice( $lv, 0, $rem );
        pnSessionSetVar( 'pncLastSeenItems', serialize( $newlv ) );
    }
    return;

}
?>
